<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="专业id" prop="specialId">
        <el-input
          v-model="queryParams.specialId"
          placeholder="请输入专业id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业名称" prop="specialName">
        <el-input
          v-model="queryParams.specialName"
          placeholder="请输入专业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业类别(本科、专科)" prop="level1Name">
        <el-input
          v-model="queryParams.level1Name"
          placeholder="请输入专业类别(本科、专科)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属大类" prop="typeDetail">
        <el-input
          v-model="queryParams.typeDetail"
          placeholder="请输入所属大类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业代码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入专业代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修业年限" prop="limitYear">
        <el-input
          v-model="queryParams.limitYear"
          placeholder="请输入修业年限"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="授予学位" prop="degree">
        <el-input
          v-model="queryParams.degree"
          placeholder="请输入授予学位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平均年薪" prop="avgSalary">
        <el-input
          v-model="queryParams.avgSalary"
          placeholder="请输入平均年薪"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="选课建议" prop="selAdv">
        <el-input
          v-model="queryParams.selAdv"
          placeholder="请输入选课建议"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="level3">
        <el-input
          v-model="queryParams.level3"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="level2">
        <el-input
          v-model="queryParams.level2"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="level1">
        <el-input
          v-model="queryParams.level1"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="2021年就业率" prop="work21">
        <el-input
          v-model="queryParams.work21"
          placeholder="请输入2021年就业率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="2022年就业率" prop="work22">
        <el-input
          v-model="queryParams.work22"
          placeholder="请输入2022年就业率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="2023年就业率" prop="work23">
        <el-input
          v-model="queryParams.work23"
          placeholder="请输入2023年就业率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别比例" prop="sexRate">
        <el-input
          v-model="queryParams.sexRate"
          placeholder="请输入性别比例"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文理比例" prop="artScienceRate">
        <el-input
          v-model="queryParams.artScienceRate"
          placeholder="请输入文理比例"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业五年月星" prop="graduateFiveSalary">
        <el-input
          v-model="queryParams.graduateFiveSalary"
          placeholder="请输入毕业五年月星"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最多就业岗位" prop="post">
        <el-input
          v-model="queryParams.post"
          placeholder="请输入最多就业岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最多就业行业" prop="mentarea">
        <el-input
          v-model="queryParams.mentarea"
          placeholder="请输入最多就业行业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最多就业地区" prop="industry">
        <el-input
          v-model="queryParams.industry"
          placeholder="请输入最多就业地区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:details:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:details:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:details:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:details:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detailsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="专业id" align="center" prop="specialId" />
      <el-table-column label="专业名称" align="center" prop="specialName" />
      <el-table-column label="专业类别(本科、专科)" align="center" prop="level1Name" />
      <el-table-column label="专业类型" align="center" prop="type" />
      <el-table-column label="所属大类" align="center" prop="typeDetail" />
      <el-table-column label="专业代码" align="center" prop="code" />
      <el-table-column label="修业年限" align="center" prop="limitYear" />
      <el-table-column label="授予学位" align="center" prop="degree" />
      <el-table-column label="平均年薪" align="center" prop="avgSalary" />
      <el-table-column label="选课建议" align="center" prop="selAdv" />
      <el-table-column label="考研方向" align="center" prop="direction" />
      <el-table-column label="社会名人" align="center" prop="celebrity" />
      <el-table-column label="开设课程" align="center" prop="course" />
      <el-table-column label="专业就业" align="center" prop="job" />
      <el-table-column label="${comment}" align="center" prop="level3" />
      <el-table-column label="${comment}" align="center" prop="level2" />
      <el-table-column label="${comment}" align="center" prop="level1" />
      <el-table-column label="${comment}" align="center" prop="skill" />
      <el-table-column label="专业简介(专业介绍)" align="center" prop="isWhat" />
      <el-table-column label="专业简介(开设课程)" align="center" prop="learnWhat" />
      <el-table-column label="专业简介(未来就业)" align="center" prop="doWhat" />
      <el-table-column label="2021年就业率" align="center" prop="work21" />
      <el-table-column label="2022年就业率" align="center" prop="work22" />
      <el-table-column label="2023年就业率" align="center" prop="work23" />
      <el-table-column label="性别比例" align="center" prop="sexRate" />
      <el-table-column label="文理比例" align="center" prop="artScienceRate" />
      <el-table-column label="专业详解" align="center" prop="content" />
      <el-table-column label="毕业五年月星" align="center" prop="graduateFiveSalary" />
      <el-table-column label="最多就业岗位" align="center" prop="post" />
      <el-table-column label="最多就业行业" align="center" prop="mentarea" />
      <el-table-column label="最多就业地区" align="center" prop="industry" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:details:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:details:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改专业详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="专业id" prop="specialId">
          <el-input v-model="form.specialId" placeholder="请输入专业id" />
        </el-form-item>
        <el-form-item label="专业名称" prop="specialName">
          <el-input v-model="form.specialName" placeholder="请输入专业名称" />
        </el-form-item>
        <el-form-item label="专业类别(本科、专科)" prop="level1Name">
          <el-input v-model="form.level1Name" placeholder="请输入专业类别(本科、专科)" />
        </el-form-item>
        <el-form-item label="所属大类" prop="typeDetail">
          <el-input v-model="form.typeDetail" placeholder="请输入所属大类" />
        </el-form-item>
        <el-form-item label="专业代码" prop="code">
          <el-input v-model="form.code" placeholder="请输入专业代码" />
        </el-form-item>
        <el-form-item label="修业年限" prop="limitYear">
          <el-input v-model="form.limitYear" placeholder="请输入修业年限" />
        </el-form-item>
        <el-form-item label="授予学位" prop="degree">
          <el-input v-model="form.degree" placeholder="请输入授予学位" />
        </el-form-item>
        <el-form-item label="平均年薪" prop="avgSalary">
          <el-input v-model="form.avgSalary" placeholder="请输入平均年薪" />
        </el-form-item>
        <el-form-item label="选课建议" prop="selAdv">
          <el-input v-model="form.selAdv" placeholder="请输入选课建议" />
        </el-form-item>
        <el-form-item label="考研方向" prop="direction">
          <el-input v-model="form.direction" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="社会名人" prop="celebrity">
          <el-input v-model="form.celebrity" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="开设课程" prop="course">
          <el-input v-model="form.course" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="专业就业" prop="job">
          <el-input v-model="form.job" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="level3">
          <el-input v-model="form.level3" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="level2">
          <el-input v-model="form.level2" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="level1">
          <el-input v-model="form.level1" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="skill">
          <el-input v-model="form.skill" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="专业简介(专业介绍)" prop="isWhat">
          <el-input v-model="form.isWhat" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="专业简介(开设课程)" prop="learnWhat">
          <el-input v-model="form.learnWhat" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="专业简介(未来就业)" prop="doWhat">
          <el-input v-model="form.doWhat" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="2021年就业率" prop="work21">
          <el-input v-model="form.work21" placeholder="请输入2021年就业率" />
        </el-form-item>
        <el-form-item label="2022年就业率" prop="work22">
          <el-input v-model="form.work22" placeholder="请输入2022年就业率" />
        </el-form-item>
        <el-form-item label="2023年就业率" prop="work23">
          <el-input v-model="form.work23" placeholder="请输入2023年就业率" />
        </el-form-item>
        <el-form-item label="性别比例" prop="sexRate">
          <el-input v-model="form.sexRate" placeholder="请输入性别比例" />
        </el-form-item>
        <el-form-item label="文理比例" prop="artScienceRate">
          <el-input v-model="form.artScienceRate" placeholder="请输入文理比例" />
        </el-form-item>
        <el-form-item label="专业详解">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="毕业五年月星" prop="graduateFiveSalary">
          <el-input v-model="form.graduateFiveSalary" placeholder="请输入毕业五年月星" />
        </el-form-item>
        <el-form-item label="最多就业岗位" prop="post">
          <el-input v-model="form.post" placeholder="请输入最多就业岗位" />
        </el-form-item>
        <el-form-item label="最多就业行业" prop="mentarea">
          <el-input v-model="form.mentarea" placeholder="请输入最多就业行业" />
        </el-form-item>
        <el-form-item label="最多就业地区" prop="industry">
          <el-input v-model="form.industry" placeholder="请输入最多就业地区" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetails, getDetails, delDetails, addDetails, updateDetails } from "@/api/gk/specialDetails";

export default {
  name: "Details",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专业详情表格数据
      detailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        specialId: null,
        specialName: null,
        level1Name: null,
        type: null,
        typeDetail: null,
        code: null,
        limitYear: null,
        degree: null,
        avgSalary: null,
        selAdv: null,
        direction: null,
        celebrity: null,
        course: null,
        job: null,
        level3: null,
        level2: null,
        level1: null,
        skill: null,
        isWhat: null,
        learnWhat: null,
        doWhat: null,
        work21: null,
        work22: null,
        work23: null,
        sexRate: null,
        artScienceRate: null,
        content: null,
        graduateFiveSalary: null,
        post: null,
        mentarea: null,
        industry: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询专业详情列表 */
    getList() {
      this.loading = true;
      listDetails(this.queryParams).then(response => {
        console.log(response)
        this.detailsList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        specialId: null,
        specialName: null,
        level1Name: null,
        type: null,
        typeDetail: null,
        code: null,
        limitYear: null,
        degree: null,
        avgSalary: null,
        selAdv: null,
        direction: null,
        celebrity: null,
        course: null,
        job: null,
        level3: null,
        level2: null,
        level1: null,
        skill: null,
        isWhat: null,
        learnWhat: null,
        doWhat: null,
        work21: null,
        work22: null,
        work23: null,
        sexRate: null,
        artScienceRate: null,
        content: null,
        graduateFiveSalary: null,
        post: null,
        mentarea: null,
        industry: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加专业详情";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetails(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改专业详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetails(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetails(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除专业详情编号为"' + ids + '"的数据项？').then(function() {
        return delDetails(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/details/export', {
        ...this.queryParams
      }, `details_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
